{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "94aeaf5c-08b9-4c35-8616-088048d2ca15",
   "metadata": {},
   "outputs": [],
   "source": [
    "from enum import Enum\n",
    "class Suite(Enum):\n",
    "    \"\"\"花色(枚举)\"\"\"\n",
    "    SPADE, HEART, CLUB, DIAMOND = range(4)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "739b2adb-fdbc-46c0-8388-580e07dea23b",
   "metadata": {},
   "outputs": [],
   "source": [
    "for suite in Suite:\n",
    "    print(f'{suite}: {suite.value}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2fec41af-b1fe-4f64-8612-5e741864308e",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Card:\n",
    "    \"\"\"牌\"\"\"\n",
    "    def __init__(self, suite, face):\n",
    "        self.suite = suite\n",
    "        self.face = face\n",
    "\n",
    "    def __repr__(self):\n",
    "        suites = '♠♥♣♦'\n",
    "        faces = ['', 'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']\n",
    "        return f'{suites[self.suite.value]}{faces[self.face]}' \n",
    "    def __lt__(self, other):\n",
    "        if self.suite == other.suite:\n",
    "            return self.face < other.face\n",
    "        return self.suite.value < other.suite.value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5969f310-e990-4ba4-8b53-50146718bd5d",
   "metadata": {},
   "outputs": [],
   "source": [
    "card1 = Card(Suite.SPADE, 5)\n",
    "card2 = Card(Suite.HEART, 13)\n",
    "print(card1, card2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37bdb3e0-7856-452f-8ce1-d44b0282610a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "class Poker:\n",
    "    \"\"\"扑克\"\"\"\n",
    "    def __init__(self):\n",
    "        self.cards = [Card(suite, face) for suite in Suite\n",
    "                      for face in range(1, 14)]\n",
    "        self.current = 0\n",
    "\n",
    "    def shuffle(self):\n",
    "        \"\"\"洗牌\"\"\"\n",
    "        self.current = 0\n",
    "        random.shuffle(self.cards)\n",
    "    def deal(self):\n",
    "        \"\"\"发牌\"\"\"\n",
    "        card = self.cards[self.current]\n",
    "        self.current += 1\n",
    "        return card\n",
    "    @property\n",
    "    def has_next(self):\n",
    "        \"\"\"还有没有牌可以发\"\"\"\n",
    "        return self.current < len(self.cards)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a2f0c81-4030-4019-8ca9-ea2c62a9daa7",
   "metadata": {},
   "outputs": [],
   "source": [
    "poker = Poker()\n",
    "poker.shuffle()\n",
    "print(poker.cards)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f133e2a-9c06-4526-b312-2e4af084446c",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Player:\n",
    "    \"\"\"玩家\"\"\"\n",
    "    def __init__(self, name):\n",
    "        self.name = name\n",
    "        self.cards = []\n",
    "    def get_one(self, card):\n",
    "        \"\"\"摸牌\"\"\"\n",
    "        self.cards.append(card)\n",
    "    def arrange(self):\n",
    "        self.cards.sort()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
